/*
 * keyboard.cpp
 *
 *  Created on: Mar 31, 2010
 *      Author: root
 */

#include "keyboard.hpp"


void c_keyboard::showid(void)
{
	my_printf("show key id is %lu\n",keyboard_id);
}


c_keyboard::c_keyboard(u32 keyboardid,const char *cname,u32 nled_show,u32 nshowtype,u32 ndefaultuser,u32 ndefaultmonitor,u32 nmaxspeed)
{
    keyboard_id=keyboardid;
    INIT_LIST_HEAD(&Comm_list_head);
    memset(&name,0x0,NAME_LENIGHT);
    memcpy(&name,cname,NAME_LENIGHT-1);
    if (nled_show) led_show=true; else led_show=false;
    showtype=nshowtype;
    nNumber_input=0;
    defaultuser = ndefaultuser;
    defaultmonitor = ndefaultmonitor ;
    maxspeed = nmaxspeed;
    last_key=KEY_CAM;
    my_printf("create keyboard id =%lu,name=%s,showtype=%d,defaultuser=%d,defaultmonitor=%d,nled_show=%d,maxspeed=%d\n"
    		              ,keyboard_id,name,showtype,defaultuser,defaultmonitor,led_show,maxspeed);
}

c_keyboard::~c_keyboard()
{
	my_printf("free keyboard id is %lu\n",keyboard_id);
};

//add port
void c_keyboard::add_port(u32 port)
{
	t_commlist* comm_list;
	comm_list = new t_commlist;
	comm_list->commmid=port;
	list_add( &(comm_list->list), &Comm_list_head);
	my_printf("keyboard %d add commport %d\n",keyboard_id,port);
}

void c_keyboard::user_key_press(key_press_char key)  //user press key
{
   switch(key)
   {
     case KEY_MON:
     {
    	 nNumber_input=0;                          //reset nNumber_input;
    	 last_key=key;
    	 break;
     }
     case  KEY_VIEW:
     {
    	 nNumber_input=0;                          //reset nNumber_input;
    	 last_key=key;
    	 break;
     }
     case KEY_CAM:
     {
    	 nNumber_input=0;                          //reset nNumber_input;
    	 last_key=key;
    	 break;
     }
     case KEY_USER_MACRO:
     {
    	 nNumber_input=0;                          //reset nNumber_input;
    	 last_key=key;
    	 break;
     }
     case KEY_SCAN:
     {
    	 nNumber_input=0;                          //reset nNumber_input;
    	 last_key=key;
    	 break;
     }
     case KEY_NUMBER_0:                            //0..9
     case KEY_NUMBER_1:
     case KEY_NUMBER_2:
     case KEY_NUMBER_3:
     case KEY_NUMBER_4:
     case KEY_NUMBER_5:
     case KEY_NUMBER_6:
     case KEY_NUMBER_7:
     case KEY_NUMBER_8:
     case KEY_NUMBER_9:
     {
    	 nNumber_input=nNumber_input*10+key;
    	 break;
     }
     case KEY_ENTER:                              //Test the  command and POST message to main.
     {
         switch(last_key)
         {
             case KEY_MON:                             //Select a monitor.
             {
                 select_mon_number=nNumber_input;
    	         break;
             }
             case KEY_CAM:                             //select a camer.
             {
                                                   //Send'a message to main,'s a switch command.
              break;
             }
             case KEY_VIEW:
             {
               break;
             }
             case KEY_USER_MACRO:
             {
               break;
             }
             default:
             {
                break;
             }

             }
          break;
          }
     default:
     {
        break;
     }


   }
}
